package com.david.system.controller;

import com.david.common.utils.MinioUtils;
import com.david.system.pojo.VO.VendorVO;
import com.david.system.service.VendorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

import static com.david.common.utils.ResultUtils.success;

@RestController
@RequestMapping("/admin/vendor")
@Slf4j
public class VendorContorller {
    @Autowired
    private VendorService vendorService;

    /**
    * @Description: 获取供应商列表
    * @Param: []
    * @return: org.springframework.http.ResponseEntity<java.lang.Object>
    * @Author: david
    * @Date: 2024/7/8
    */
    @GetMapping("/list")
    public ResponseEntity<Object> getVendorList() {
        List<VendorVO> vendorVOList = vendorService.getVendorList();
        return success(true, vendorVOList);
    }

    /**
    * @Description: 修改供应商信息
    * @Param: [vendorVO]
    * @return: org.springframework.http.ResponseEntity<java.lang.Object>
    * @Author: david
    * @Date: 2024/7/8
    */
    @PostMapping("/edit")
    public ResponseEntity<Object> editVendor(@RequestBody VendorVO vendorVO) {
        log.info("修改供应商信息:{}", vendorVO);
        vendorService.editVendor(vendorVO);
        return success(true, "修改完成");
    }

    /**
    * @Description: 删除供应商
    * @Param: [id]
    * @return: org.springframework.http.ResponseEntity<java.lang.Object>
    * @Author: david
    * @Date: 2024/7/8
    */
    @DeleteMapping("/{id}")
    public ResponseEntity<Object> delVendor(Integer id) {
        log.info("删除{}号供应商",id);
        vendorService.delVendor(id);
        return success(true,"供应商删除成功");
    }

    /**
    * @Description: 新增供应商
    * @Param: [vendorVO]
    * @return: org.springframework.http.ResponseEntity<java.lang.Object>
    * @Author: david
    * @Date: 2024/7/8
    */    
    @PostMapping("/add")
    public ResponseEntity<Object> addVendor(@RequestBody VendorVO vendorVO) {
        log.info("新增供应商{}",vendorVO);
        vendorService.addVendor(vendorVO);
        return success(true, "新增供应商成功");
    }


}
